package com.macro.mall.common.api;

public class CommonResuIt<T> {

    /**
     * 状态码
     */
    private long code;
    /**
     * 提示信息
     */
    private String message;
    /**
     * 数据封装
     */
    private T data;

    protected  CommonResuIt(){
    }

    protected  CommonResuIt(long code, String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功后返回结果
     * @param data
     * @param <T>
     * @return
     */
    public static <T> CommonResuIt<T> success(T data){
        return new CommonResuIt<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }

    /**
     * 成功返回结果
     * @param data
     * @param message
     * @param <T>
     * @return
     */
    public static <T> CommonResuIt<T> success(T data,String message){
        return new CommonResuIt<T>(ResultCode.SUCCESS.getCode(), message,data);
    }

    /**
     * 失败后返回结果
     * @param errorCode
     * @param <T>
     * @return
     */
    public static <T> CommonResuIt<T> failed(IErrorCode errorCode){
        return new CommonResuIt<T>(errorCode.getCode(),errorCode.getMessage(),null);
    }
}
